import axios from 'axios'
import { baseURL } from './const'

const service = axios.create({
   baseURL: baseURL,
})

service.interceptors.response.use((response) => {
   if (response.status === 200) {
      return response.data.data.problemsetQuestionList.questions
   } else {
      alert('error')
      return []
   }
})

export function axiosPost(variables = {}) {
   return service.post(baseURL, {
      query: '\n    query problemsetQuestionList($categorySlug: String, $limit: Int, $skip: Int, $filters: QuestionListFilterInput) {\n  problemsetQuestionList(\n    categorySlug: $categorySlug\n    limit: $limit\n    skip: $skip\n    filters: $filters\n  ) {\n    hasMore\n    total\n    questions {\n      acRate\n      difficulty\n      freqBar\n      frontendQuestionId\n      isFavor\n      paidOnly\n      solutionNum\n      status\n      title\n      titleCn\n      titleSlug\n      topicTags {\n        name\n        nameTranslated\n        id\n        slug\n      }\n      extra {\n        hasVideoSolution\n        topCompanyTags {\n          imgUrl\n          slug\n          numSubscribed\n        }\n      }\n    }\n  }\n}\n',
      variables: variables,
      operationName: 'problemsetQuestionList',
   })
}
